#include <stdio.h>
#include "lib/confdata.h"

static void dumplist (cdsl_dlist_t *list, const char *label)
{
  cdsl_dlist_node_t *p;
  int i = 0;
  for (p = cdsl_dlist_begin (list); p != cdsl_dlist_end (list); p = cdsl_dlist_next (p))
    {
      printf ("%s (%d): '%s'\n", label, i++, (const char *)cdsl_dlist_value (p));
    }
}

run2_confdata_t * populate (void)
{
  run2_confdata_t * confdata;
  run2_selfoptions_t * selfopt;
  run2_global_t * global;
  run2_env_t * env;
  run2_env_spec_t * envspec;
  run2_tgtopts_t * tgtopts;
  run2_tgt_spec_t * tgtspec;

  confdata = run2_confdata_create ();

  selfopt = run2_confdata_get_selfoptions (confdata);
  run2_selfoptions_add_arg (selfopt, "--debug=2");
  run2_selfoptions_add_arg (selfopt, "--wait");

  global = run2_confdata_get_global (confdata);
  env = run2_global_get_env (global);
  envspec = run2_env_get_var (env, "RUN2a");
  run2_env_spec_set (envspec, "yes");
  envspec = run2_env_get_var (env, "RUN2b");
  run2_env_spec_set (envspec, "value");
  run2_env_spec_prepend (envspec, "a|");
  run2_env_spec_prepend (envspec, "b|");
  run2_env_spec_append (envspec, "|c");
  run2_env_spec_append (envspec, "|d");
  envspec = run2_env_get_var (env, "PATH");
  run2_env_spec_set (envspec, "/bin");
  run2_env_spec_prepend (envspec, "/usr/local/bin");
  run2_env_spec_prepend (envspec, "/home/user/bin");
  run2_env_spec_append (envspec, "/usr/sbin");
  run2_env_spec_append (envspec, "/usr/libexec");

  tgtopts = run2_confdata_get_gdi (confdata);
  env = run2_tgtopts_get_env (tgtopts);
  envspec = run2_env_get_var (env, "TERM");
  run2_env_spec_prepend (envspec, "rxvt-cygwin-native");
  tgtspec = run2_tgtopts_get_tgt (tgtopts);
  run2_tgt_spec_set_filename (tgtspec, "/usr/bin/rxvt.exe");
  run2_tgt_spec_set_startin  (tgtspec, "~");
  run2_tgt_spec_add_arg (tgtspec, "-display :0");
  run2_tgt_spec_add_arg (tgtspec, "-fn \"DejaVu LGC Sans Mono\"");
  run2_tgt_spec_add_arg (tgtspec, "-tn rxvt-cygwin-native");
  run2_tgt_spec_add_arg (tgtspec, "-e /bin/bash --login");

  tgtopts = run2_confdata_get_x11 (confdata);
  env = run2_tgtopts_get_env (tgtopts);
  envspec = run2_env_get_var (env, "TERM");
  run2_env_spec_prepend (envspec, "rxvt-unicode");
  tgtspec = run2_tgtopts_get_tgt (tgtopts);
  run2_tgt_spec_set_filename (tgtspec, "/usr/bin/urxvtc-X.exe");
  run2_tgt_spec_set_startin  (tgtspec, "~");
  run2_tgt_spec_add_arg (tgtspec, "-display 127.0.0.1:0.0");
  run2_tgt_spec_add_arg (tgtspec, "-ls");
  run2_tgt_spec_add_arg (tgtspec, "-e /bin/bash --login");

  return confdata;
}

void cleanup (run2_confdata_t * d)
{
  run2_confdata_delete (d);
}

int main (int argc, char * argv[])
{
  run2_set_program_name (argv[0]);
  run2_confdata_t * confdata;
  confdata = populate();
  run2_confdata_print (stderr, 0, "Run2Config", confdata);
  cleanup (confdata);
  return 0;
}
